/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:59 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DiemdanhDAL : SqlProvider<DiemdanhEntity>
    {
        static DiemdanhDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DiemdanhEntity entity = new DiemdanhEntity();
                entity.PK_iDiemdanhID = Int64.Parse("0" + dr["PK_iDiemdanhID"].ToString());
				entity.FK_iTrangslideID = Int64.Parse("0"+dr["FK_iTrangslideID"].ToString());
				entity.FK_iHocvienID = Int64.Parse("0"+dr["FK_iHocvienID"].ToString());
                entity.FK_iKhoahocID = Int64.Parse("0" + dr["FK_iKhoahocID"].ToString());
                entity.dThoidiemxem = String.IsNullOrEmpty(dr["dThoidiemxem"].ToString()) ? DateTime.Now : DateTime.Parse(dr["dThoidiemxem"].ToString());
				entity.iTrangthai = Int16.Parse("0"+dr["iTrangthai"].ToString());
                return entity;
            };
        }
        public static DiemdanhEntity GetOne(Int64 PK_iDiemdanhID)
        {
            string cmdName = "spDiemdanh_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDiemdanhID", PK_iDiemdanhID);
            DiemdanhEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DiemdanhEntity> GetAll()
        {
            string cmdName = "spDiemdanh_Get";
            return GetList(cmdName);
        }
        public static List<DiemdanhEntity> GetByFK_iHocvienID(Int64 FK_iHocvienID)
		{
			string cmdName = "spDiemdanh_GetByFK_FK_iHocvienID";
			SqlParameter p = new SqlParameter("@FK_iHocvienID",FK_iHocvienID);
			List<DiemdanhEntity> list = GetList(cmdName, p);
			return list;
		}
        public static List<DiemdanhEntity> GetByFK_iKhoahocID(Int64 FK_iKhoahocID)
        {
            string cmdName = "spDiemdanh_GetByFK_iKhoahocID";
            SqlParameter p = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            List<DiemdanhEntity> list = GetList(cmdName, p);
            return list;
        }
        public static List<DiemdanhEntity> GetByFK_iKhoahocIDAndFK_iHocvienID(Int64 FK_iKhoahocID, Int64 FK_iHocvienID)
        {
            string cmdName = "spDiemdanh_GetByFK_iKhoahocIDAndFK_iHocvienID";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            p[1] = new SqlParameter("@FK_iHocvienID", FK_iHocvienID);
            List<DiemdanhEntity> list = GetList(cmdName, p);
            return list;
        }
        public static List<DiemdanhEntity> GetByFK_iKhoahocIDAndFK_iHocvienIDAndFK_iTrangslideID(Int64 FK_iKhoahocID, Int64 FK_iHocvienID, Int64 FK_iTrangslideID)
        {
            string cmdName = "spDiemdanh_GetByFK_iKhoahocIDAndFK_iHocvienIDAndFK_iTrangslideID";
            SqlParameter[] p = new SqlParameter[3];
            p[0] = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            p[1] = new SqlParameter("@FK_iHocvienID", FK_iHocvienID);
            p[2] = new SqlParameter("@FK_iTrangslideID", FK_iTrangslideID);
            List<DiemdanhEntity> list = GetList(cmdName, p);
            return list;
        }
        public static int Add(DiemdanhEntity entity)
        {
            string cmdName = "spDiemdanh_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DiemdanhEntity entity)
        {
            string cmdName = "spDiemdanh_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iDiemdanhID)
        {
            string cmdName = "spDiemdanh_Delete";
            SqlParameter p = new SqlParameter("@PK_iDiemdanhID", PK_iDiemdanhID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DiemdanhEntity entity)
        {
            SqlParameter[] p = new SqlParameter[6];
			p[0] = new SqlParameter("@PK_iDiemdanhID", entity.PK_iDiemdanhID);
			p[1] = new SqlParameter("@FK_iHocvienID", entity.FK_iHocvienID);
			p[2] = new SqlParameter("@dThoidiemxem", entity.dThoidiemxem);
			p[3] = new SqlParameter("@iTrangthai", entity.iTrangthai);
            p[4] = new SqlParameter("@FK_iKhoahocID", entity.FK_iKhoahocID);
            p[5] = new SqlParameter("@FK_iTrangslideID", entity.FK_iTrangslideID);
            return p;
        }
        #endregion
       
    }
}